
#include <stdio.h>
#include "base/abc/abc.h"
#include "base/main/main.h"



//resyn2优化
extern Abc_Ntk_t *Optimaize_resyn2(Abc_Ntk_t *pNtk)
{
    Abc_Ntk_t *pNtkTemp = NULL;

	//优化电路
	if ( !Abc_NtkIsStrash(pNtk) )
    {
        pNtk = Abc_NtkStrash( pNtkTemp = pNtk, 0, 1, 0 );
        Abc_NtkDelete( pNtkTemp );
    }
	
	//balance
	pNtk = Abc_NtkBalance( pNtkTemp = pNtk, 0, 0, 0 );  Abc_NtkDelete( pNtkTemp );
	//rewrite -l
    if ( !Abc_NtkRewrite( pNtk, 1, 0, 0, 0, 0 ) )
    {
        Abc_Print( -1, "Rewriting has failed.\n" );
        return NULL;
    }
	
	//refactor -l
    if ( !Abc_NtkRefactor( pNtk, 10, 16, 1, 0, 0, 0 ) )
    {
        Abc_Print( -1, "Refactoring has failed.\n" );
        return NULL;
    }
	//balance
	pNtk = Abc_NtkBalance( pNtkTemp = pNtk, 0, 0, 0 );  Abc_NtkDelete( pNtkTemp );
	//rewrite -l
    if ( !Abc_NtkRewrite( pNtk, 1, 0, 0, 0, 0 ) )
    {
        Abc_Print( -1, "Rewriting has failed.\n" );
        return NULL;
    }
	//rewrite -lz
    if ( !Abc_NtkRewrite( pNtk, 1, 1, 0, 0, 0 ) )
    {
        Abc_Print( -1, "Rewriting has failed.\n" );
        return NULL;
    }
	
	//balance
	pNtk = Abc_NtkBalance( pNtkTemp = pNtk, 0, 0, 0 );  Abc_NtkDelete( pNtkTemp );
	//refactor -lz
    if ( !Abc_NtkRefactor( pNtk, 10, 16, 1, 1, 0, 0 ) )
    {
        Abc_Print( -1, "Refactoring has failed.\n" );
        return NULL;
    }
	//rewrite -lz
    if ( !Abc_NtkRewrite( pNtk, 1, 1, 0, 0, 0 ) )
    {
        Abc_Print( -1, "Rewriting has failed.\n" );
        return NULL;
    }
	//balance
	pNtk = Abc_NtkBalance( pNtkTemp = pNtk, 0, 0, 0 );  Abc_NtkDelete( pNtkTemp );
	Abc_NtkPrintStats( pNtk, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
	
	return pNtk;
}


///////////////////////////////////////////////////////






